#include <Windows.h>
#include <MMSystem.h>
#include "ICore.h"

void EnterMessageLoop()
{
	MSG Msg;
	memset(&Msg,0,sizeof(Msg));
	bool run = true;

	DWORD dwCurrTime = timeGetTime();
	DWORD dwPrevTime = dwCurrTime;

	while (run)
	{
		while(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
		{
			if (Msg.message == WM_QUIT)
			{
				run = false;
				break;
			}
			TranslateMessage(&Msg);
			DispatchMessage(&Msg);
		}
		dwCurrTime = timeGetTime();
		DWORD dtime = dwCurrTime - dwPrevTime;
		ICore::GetInstance().Updata(dtime/1000);
		ICore::GetInstance().PrvRender();
		ICore::GetInstance().Render();
		ICore::GetInstance().EndRender();
		//TODO:
		dwPrevTime = dwCurrTime;

		
	}

}
int CALLBACK WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
	
	if(ICore::GetInstance().Initialize())
	{
		EnterMessageLoop();
		ICore::GetInstance().Terminate();
		//TODO:
	}
	
	return 0;
}